<%@page import="java.util.List"%>
<%@page import="com.xsprite.managesys.bean.XlsxFileBean"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>workbench</title>
<link rel="stylesheet" type="text/css" href="css/easyui.css">
<link rel="stylesheet" type="text/css" href="css/icon.css">
<link rel="stylesheet" type="text/css" href="css/demo.css">
<style type="text/css">
div.console1, div.console2, div.console3 {
	word-wrap: break-word;
}
/* First console */
div.console1 {
	font-size: 14px
}

div.console1 div.jquery-console-inner {
	width: 900px;
	height: 200px;
	background: #333;
	padding: 0.5em;
	overflow: auto
}

div.console1 div.jquery-console-prompt-box {
	color: #fff;
	font-family: monospace;
}

div.console1 div.jquery-console-focus span.jquery-console-cursor {
	background: #fefefe;
	color: #333;
	font-weight: bold
}

div.console1 div.jquery-console-message-error {
	color: #ef0505;
	font-family: sans-serif;
	font-weight: bold;
	padding: 0.1em;
}

div.console1 div.jquery-console-message-value {
	color: #1ad027;
	font-family: monospace;
	padding: 0.1em;
}

div.console1 div.jquery-console-message-type {
	color: #52666f;
	font-family: monospace;
	padding: 0.1em;
}

div.console1 span.jquery-console-prompt-label {
	font-weight: bold
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.console.js"></script>
<script type="text/javascript" src="js/comet4j.js"></script>
<script type="text/javascript">
	function show(message) {
		$.messager.show({
			title : '消息',
			msg : message,
			showType : 'show'
		});
	}

	var console1;

	$(document).ready(
			function() {
				$('#w').window('close');
				$('#t1').datagrid({
					singleSelect : (this.value == 1)
				});
				$('#t2').datagrid({
					singleSelect : (this.value == 1)
				});
				$('#importToDb').click(
						function() {
							var rows = $('#t1').datagrid('getChecked');
							var rowServers = $('#t2').datagrid('getChecked');
							if (rows.length == 0 || rowServers.length == 0) {
								$("#console").append("请先选择文件或服务器\n");
								return;
							}
							var requestParams = "{\"transferFiles\":";
							requestParams += "["
							$.each(rows, function(index, value) {
								requestParams += "{\"tag\"" + ":\""
										+ value['id'] + "\"},";
							});
							requestParams = requestParams.substring(0,
									requestParams.length - 1);
							requestParams += "]";

							requestParams += ",";
							requestParams += "\"updateServers\":";
							requestParams += "[";
							$.each(rowServers, function(index, value) {
								requestParams += "{\"tag\"" + ":\""
										+ value['serverName'] + "\"},";
							});
							requestParams = requestParams.substring(0,
									requestParams.length - 1);
							requestParams += "]";
							requestParams += "}";
							var url = "TransferDBServlet?paras="
									+ requestParams;
							$.post(url, function(data) {
								$('#w').window('open');
								$('#w').html(data);
							});
						});
				$('#deleteXlsxFiles').click(
						function() {
							var rows = $('#t1').datagrid('getChecked');
							if (rows.length == 0) {
								return;
							}
							var requestParams = "{\"deleteFiles\":";
							requestParams += "["
							$.each(rows, function(index, value) {
								requestParams += "{\"tag\"" + ":\""
										+ value['id'] + "\"},";
							});
							requestParams = requestParams.substring(0,
									requestParams.length - 1);
							requestParams += "]";
							requestParams += "}";
							$.post("DeleteXlsxFilesServlet?paras="
									+ requestParams, function(data) {
								$('#w').window('open');
								$('#w').html(data);
								$('#t1').datagrid("reload");
							});
						});
			});
</script>
</head>
<body>

	<div style="width: 100%; float: left; height: 980px">
		<form action="UploadFileServlet" method="post"
			enctype="multipart/form-data" style="display: inline;">
			<input id="fb" class="easyui-filebox" style="width: 980px"
				data-options="prompt:'Choose a file...'" name="file1"><br />
			<!-- <input id="fb" class="easyui-filebox" style="width:400px" data-options="prompt:'Choose a file...'" name="file2" ><br/>
				<input id="fb" class="easyui-filebox" style="width:400px" data-options="prompt:'Choose a file...'" name="file3"><br/> -->
			<input type="submit" value="上传文件"><a type="button"
				id="deleteXlsxFiles" class="easyui-linkbutton">删除excel</a>
		</form>
		<div style="width: 100%;">
			<form id="transferForm" action="transferDBServlet" method="post"
				entyctype="text/plain">
				<table id="t1" title="已上传文件" style="width: 100%; height: 300px"
					data-options="rownumbers:true,singleSelect:true,autoRowHeight:true,pagination:true,pageSize:10,
																								url:'GetXlsxFilesServlet', method:'get'">
					<thead>
						<tr>
							<th data-options="field:'ck',checkbox:true"></th>
							<th data-options="field:'id',width:20">id</th>
							<th data-options="field:'filename',width:150">文件名</th>
							<th data-options="field:'fileSize',width:50">文件大小</th>
							<th data-options="field:'uploadDateStr',width:200,align:'right'">上传时间</th>
						</tr>
					</thead>
				</table>

				<table id="t2" title="选择需要更新的服务器" style="width: 100%; height: 300px"
					data-options="rownumbers:true,singleSelect:true,autoRowHeight:true,pagination:true,pageSize:10,
																											url:'GetServersServlet',method:'get'">
					<thead>
						<tr>
							<th data-options="field:'ck',checkbox:true"></th>
							<th data-options="field:'serverName',width:80">服务器名</th>
							<th data-options="field:'url',width:350">服务器地址</th>
						</tr>
					</thead>
				</table>
				<a type="button" id="importToDb" class="easyui-linkbutton">导入数据库</a>
			</form>

		</div>
	</div>
	<div id="w" class="easyui-window" title="Basic Window"
		data-options="iconCls:'icon-save'"
		style="width: 500px; height: 200px; padding: 10px;" maximized="true"
		collapsible="false" minimizable="false">The window content.</div>
</body>
</html>